/**
 * sem_stubs.h - stubs for memory management.
 *
 *  Copyright (C) 2008  ZhangHu
 *  All rights reserved.
 *  E-MAIL: anmnmnly@gmail.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef __SEM_STUBS_H__
#define __SEM_STUBS_H__

#define kmalloc malloc
#define kfree  free
#define kmemset memset
#define mac_disable_irq()
#define mac_enable_irq()
#define MAX_PRIO 64


/* Task status */
#define T_READY  0x01
#define T_BLOCK  0x02
#define T_SLEEP  0x04



typedef struct task_ctrl_blk {
	int id;
	int prio;
	list_t link;
	slist_t sem_link;
	uword_t status;
} tcb_t;



#define TASK_NR 5
static tcb_t tcb_array[TASK_NR];
static int task_id[TASK_NR];
static int task_prio[TASK_NR];

static tcb_t *ptcb = NULL;
static list_t sleep;

static void stubs_init(void)
{
    int i;
    for(i=0; i<TASK_NR; i++) {
        tcb_array[i].id = task_id[i] = 100 * i;
        tcb_array[i].prio = task_prio[i] = (i * 15) % 64;
        tcb_array[i].link.next = &ptcb[i].link;
        tcb_array[i].link.prev = &ptcb[i].link;
    	tcb_array[i].sem_link.next = NULL;
    	tcb_array[i].status = T_READY;
    }
    ptcb = &tcb_array[0];

    sleep.next = &sleep;
    sleep.prev = &sleep;
}



static tcb_t *current(void) {
    return ptcb;
}



static void set_task(int index) {
    ptcb = &tcb_array[index];
}



static list_t *del_tcb_rdy(tcb_t *tcb) {
	return &ptcb->link;
}



static void add_tcb_rdy(tcb_t *ptcb) {

}



static void scheduler(void) {

}



static void add_tcb_sleep(tcb_t *ptcb) {
    add_node_list_rear(&sleep, &ptcb->link);
}



#endif
